package com.yao.consumer.controller;


import domain.User;
import org.apache.dubbo.config.annotation.Method;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import service.UserService;

/**
 * @author yao
 */
@RestController
public class UserControllerA {
    /**
     * use annotation  @Reference to look up service from registry ,you also can use filed version to assign which version
     */
    @Reference(version = "2.0" // 表明使用的提供者的版本（多版本控制，灰度升级）
            , check = false // 标识对是否有提供者进行检查
            , group = "A"// 表明所使用的提供者的组
            , protocol = "dubbo" // 调用的协议
            , methods = {@Method(name = "sayHello", timeout = 3000)}// 针对接口中方法进行设置
            // ,mock = "return null"  //配置降级策略,直接返回null
            // ,mock = "true"  //配置mock类,将会执行降级类中方法
            ,cache = "ture"  // 开启缓存，也可以配置方法级别，默认缓存1000个

    )
    private UserService userService;

    @GetMapping("/helloA")
    @ResponseBody
    public String hello(@RequestParam String name) {
        String sayHello = userService.sayHello(new User(name));
        if (sayHello == null){
            return "降级";
        }
        return sayHello;

    }
}
